package cn.edu.zucc.controller;

import cn.edu.zucc.dao.EduExpMapper;
import cn.edu.zucc.dao.eduexp.EduExpMapperExamp;
import cn.edu.zucc.dao.eduexp.model.EduExpExample;
import cn.edu.zucc.entity.EduExp;
import cn.edu.zucc.service.EduExpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description edu_exp
 * @author zhengkai.blog.csdn.net
 * @date 2022-04-13
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/eduExp")
public class EduExpController2 {

    @Resource
    private EduExpService eduExpService;
    @Resource
    private EduExpMapper eduExpMapper;

    /**
     * 新增
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/insert")
    public Object insert(EduExp eduExp){
        return eduExpService.insert(eduExp);
    }

    /**
     * id 存在就更新 不然插入
     * @param eduExp
     * @return
     */
    @PostMapping("/save")
    public Object save(@RequestBody  EduExp eduExp){
        return eduExpService.save(eduExp);
    }

    /**
     * 刪除
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/delete")
    public Object delete(int id){
        return eduExpService.delete(id);
    }

    /**
     * 更新
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/update")
    public Object update(EduExp eduExp){
        return eduExpService.update(eduExp);
    }

    /**
     * 查询 根据主键 id 查询
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/load")
    public Object load(int id){
        return eduExpService.load(id);
    }

//    @Resource
//    @Autowired
//EduExpMapperExamp eduExpMapper;

    @PostMapping("/getByStuId")
    public Object getByStuId(@RequestBody  EduExp eduExp){
//        eduExpService.pageList()
        List<EduExp> eduExps = eduExpMapper.selectByStuId(eduExp.getStuId());
//        EduExpExample eduExpExample = new EduExpExample();
//        eduExpExample.createCriteria().
//         eduExpExample.createCriteria().andStuIdEqualTo(eduExp.getStuId());
//        return eduExpMapper.selectByExample(eduExpExample);
        Map<String ,Object>map=new HashMap<>();
        map.put("content",eduExps);
//        return eduExps;
        return map;
    }

    /**
     * 查询 分页查询
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/list")
//    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int pageNumber,
    public Object pageList(@RequestParam(required = false, defaultValue = "0") int pageNumber,
                                        @RequestParam(required = false, defaultValue = "10") int pageSize) {
//        data.content
//        Map<String, Object>map=new HashMap<>();
//        Map<String, Object> pageList = eduExpService.pageList(pageNumber, pageSize);
//        return ReturnT.success(pageList);
//        map.put("data",pageList);
        return eduExpService.pageList(pageNumber, pageSize);
//        return map;

    }

}
